﻿Imports System.ComponentModel.Composition
Imports System.Collections.ObjectModel
Imports Pronama.NamaAlert.AddIn.ViewModel

<AddInExport("{47A0ED3F-E579-460D-87FE-C852C989ED48}", "Dfault Alert",
    Description:="",
    HasSetting:=False,
    HasContent:=True)>
<Export(GetType(IDestinationAddIn))>
Public Class DefaultAlert
    Implements IDestinationAddIn

    Private Activated As Boolean
    Private AlertTargets As New ObservableCollection(Of AlertTargetViewModel)

    Private Settings As ISettings
    Private Helper As IHelper

#Region "Implementation"

    <Import(GetType(PostMessageCallback))>
    Property PostMessage As PostMessageCallback Implements IDestinationAddIn.PostMessage

    Public Event Deactivated(ByVal sender As Object, ByVal e As System.EventArgs) Implements IAddIn.Deactivated
    Protected Sub OnDeactivated(ByVal e As EventArgs)
        RaiseEvent Deactivated(Me, e)
    End Sub

    Public Sub Initialize(ByVal settings As ISettings, ByVal helper As IHelper) Implements IAddIn.Initialize
        Me.Settings = settings
        Me.Helper = helper
    End Sub

    Public Sub Activate() Implements IAddIn.Activate
        Activated = True
    End Sub

    Public Sub Deactivate() Implements IAddIn.Deactivate
        Activated = False
    End Sub

    Public Function GetContentControl(ByVal message As Message) As System.Windows.Controls.Control Implements IAddIn.GetContentControl

        For i = 0 To 49
            Dim a = New AlertTargetViewModel
            a.Name = "あいうえお"
            a.Id = i.ToString

            AlertTargets.Add(a)
        Next

        Return New DefaultAlertContentPage With {.DataContext = AlertTargets}
    End Function

    Public Function GetSettingControl() As System.Windows.Controls.Control Implements IAddIn.GetSettingControl
        Throw New NotSupportedException
    End Function

    Public Function GetSidebarControl() As System.Windows.Controls.Control Implements IAddIn.GetSidebarControl
        Throw New NotSupportedException
    End Function

    Public Sub ReceiveMessage(ByVal sourceAddIn As IAddIn, ByVal message As Message) Implements IDestinationAddIn.ReceiveMessage

    End Sub

    Public Sub WriteLog(ByVal sourceAddIn As IAddIn, ByVal log As Log) Implements IDestinationAddIn.WriteLog

    End Sub

#End Region

    Private Function GetMetadata(ByVal sourceAddIn As IAddIn) As AddInExportAttribute
        Dim attr = sourceAddIn.GetType.GetCustomAttributes(GetType(AddInExportAttribute), True)
        If attr.Count = 0 Then
            Return Nothing
        End If
        Return DirectCast(attr.First, AddInExportAttribute)
    End Function





End Class
